<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>蒋路的挂号页面</title>
</head>
<body>
	<script type="text/javascript">  
     var zhuangtai=0;
	$.extend($.fn.validatebox.defaults.rules, {
		ChackksByyg: { 
	        validator: function(value){	
	        	var ygYnBox=$("#rerePhysician").combobox("getText");
	        	var ksYnBox=$("#rereAdministrative").combobox("getText");
	        	
	        	if((ygYnBox=="")||(ksYnBox!="" && ygYnBox!=""&&zhuangtai==0)){
	        		$.ajax({
		                type: "Post",
		                url: "to_nameTofindALLdepartment",
		                data: {departmentName:value },
		                success: function (data) {
		                  	        $('#rerePhysician').combobox({  
		                            url: 'to_bmidToTbstaff?departmentNo=' + data[0].departmentNo,  
		                            editable: false,  
		                            method: 'get',  
		                            valueField: 'staffNo',  
		                            textField: 'staffName',  
		                        });  	                    
		                }
		            });	
	        	}
	        	zhuangtai=0;		        		        	        	 
	        }
	    }
	});
	
	$.extend($.fn.validatebox.defaults.rules, {
		ChackynYg: { 
	        validator: function(value){	
	        	zhuangtai=1;
	        	$.ajax({
	                type: "Post",
	                url: "to_useygnameToTbstaff",
	                data: {staffName:value},
	                success: function (data) {
	                    var hqid=data[0].departmentNo;
	                    $.ajax({
	   	                 type: "Post",
	   	                 url: "to_idTofindALLdepartment",
	   	                 data: {bmid:hqid},
	   	                 success: function (data) {	   	                
	   	                	 var bmName=data[0].departmentName;
	   	                     $("#rereAdministrative").combobox("setText",bmName);
		                 
	   	                 }
	   	             });
	                }
	            });
	        	 
	        },
	    }
	});
	
	$.extend($.fn.validatebox.defaults.rules, {
		ChackreIc: {
	        validator: function(value){
	        	  if(value==null){    		  
	        		  return false;
	        	  }else{
	        		  $.ajax({
					        type: "Post",
					        url: "findMaxStuByPage",
					        data: {},
					        success: function (data) {
					        	
					        	if(value>data){
					        		$.messager.alert("温馨提示", "你输入的卡号不存在！");
					        	}else{
					        		$.ajax({
									        type: "Post",
									        url: "findMaxregtimByPage",
									        data: {},
									        success: function (data) {	
									        	var text = $("#rereDate").textbox('getValue');
									        	var oDate1 = new Date(data);  
									        	var oDate2 =new Date(text);
									        	var date1y=oDate1.getFullYear();
									        	var date1m=oDate1.getMonth();
									        	var date1d=oDate1.getDate();
									        	var date2y=oDate2.getFullYear();
									        	var date2m=oDate2.getMonth();
									        	var date2d=oDate2.getDate();									        	
									        	if(date1y==date2y && date1m==date2m && date1d==date2d){
									        		$.ajax({
									                    type: "Post",
									                    url: "findMaxreghjhByPage",
									                    data: {  },
									                    success: function (data) {
									                    $("#rereCallNum").textbox("setValue",data+1);
									                    }
									                });
									        	 }else{	
									        		 $("#rereCallNum").textbox("setValue",1);
									        	 }
									        	 
									        	 

									        },
								    });
					        		
					        	}
					        	
					        },
					  });	        		  
	        		  return true;
	        	  }
	        	   
	        },
	        message: '卡号不能为空！'
	    }
	});

	
		$(function(){
			var date = new Date();		
			var y = date.getFullYear();  
			var m = date.getMonth() + 1;  
			m = m < 10 ? '0' + m : m;  
			var d = date.getDate();  
			d = d < 10 ? ('0' + d) : d;  
			var needDate=y + '-' + m + '-' + d; 		   
			$("#addregistration").linkbutton({
				onClick:function(){															
					$('#reginwin').window({'title': "挂号"});
					$("#reginwin").window('open');
					$("#regstuff").form("clear");
					$("#rereDate").textbox("setValue",needDate );
					
					var showygid=$("#tontyiStaffId").html();
					$.ajax({
		                type: "Post",
		                url: "to_idToTbstaff",//根据id获取名字
		                data: {staffNo:showygid},
		                success: function (data) {
		                    $("#rereFigurePerson").textbox("setText",data[0].staffName);
		                }
		            });
				}
			});
			$("#regstu-save").linkbutton({  
				onClick : function() {
					
					var xys=($("#rerePhysician").combobox("getText"));
					$("#rerePhysician").combobox("setValue",xys);
					var xks=($("#rereAdministrative").combobox("getText"));
					$("#rereAdministrative").combobox("setValue",xks);
					var xyg=($("#rereFigurePerson").textbox("getText"));
					$("#rereFigurePerson").textbox("setValue",xyg);
					
					$('#regstuff').form('submit', {
						onSubmit : function() {
						},				
						success : function(data) {
							var json = eval("("+data+")");
							$.messager.alert("提示", json.reason);
							var callnum=$("#rereCallNum").textbox("getText");
							//关闭窗口
							$("#reginwin").window('close');
							//重新加载数据
							$("#regtab").datagrid("reload");
							$(this).form("clear");
							$("#regtab").datagrid({
							       rowStyler: function (index, row) {
							            if (row.reCallNum== callnum) {
							                 return 'background-color:#6293BB;color:#fff;';
							            }
							       }
							}); 
							
							
						}
					});
				}
			});
		
			
			$("#regiccarddeltool").linkbutton({onClick: function(){
				var rows = $("#regtab").datagrid("getSelections");
				  if(rows.length>0){
					 $.messager.confirm("提示", "确定要删除吗？", function(v){
						if(v){
							    //获取所有选中的编号
							    var rows = $("#regtab").datagrid("getSelections");	
								//将编号保存到数组中
								var arr = [];
								for(var i = 0; i < rows.length; i ++){
									arr.push(rows[i].reId);
								}
								//用form提交
								$('<form>').form('submit', {
								    url:'delregin',
								    onSubmit: function(param){
								    	param.list=arr;
								    },
								    success:function(data){
								    	var json = eval("(" + data + ")");
										$.messager.alert("提示", json.reason);
										$("#regtab").datagrid("reload");
								    }});
						  }
					});
					
				  }
			      else{$.messager.alert("提示", "请选择需要删除的记录！"); }
			}});
	
			
			$("#regcancel").linkbutton({
				onClick : function() {
					$('#regstuff').form("clear");
					$("#reginwin ").window("close");
				}
			});
			$("#regref").linkbutton({
				onClick:function(){
					$("#regtab").datagrid({
						 url: 'toreginpage'
					});
				}
			});
			$('#regsearch').searchbox({
			    searcher:function(value,name){
			    	if(name=="科室"){
			    		$("#regtab").datagrid({
				    		url:'findbyreks',
				    		queryParams: {
				    			price: value
				    		}
				    	});
			    	}else if(name=="医师"){
			    		$("#regtab").datagrid({
				    		url:'findbyreys',
				    		queryParams: {
				    			price: value
				    		}
				    	});
			    	}else if(name=="挂号方式"){
			    		$("#regtab").datagrid({
				    		url:'findbyrefs',
				    		queryParams: {
				    			price: value
				    		}
				    	});
			    	}else if(name=="缴费情况"){
			    		$("#regtab").datagrid({
				    		url:'findbyrejf',
				    		queryParams: {
				    			price: value
				    		}
				    	});
			    	}			    	
			    	
			    }
			});
		});
	</script>
	
	  <table id="regtab" class="easyui-datagrid"
			data-options="
				fitColumns:true,
				fit:true,
				rownumbers: true,
			    url: 'toreginpage',
				border:false ,
				pagination:true,
				toolbar: '#regjl_btn',
				pageSize: 15,
				pageList:[15,30,45,60]
			">
			<thead>            
				<tr> 
					<th class="ident" data-options="field:'reId',checkbox:true">挂号编号</th>
					<th class="ident" data-options="field:'rePhysician'">挂号医师</th>
					<th class="ident" data-options="field:'reWay'">挂号方式</th>
					<th class="ident" data-options="field:'ireId',width:10">Ic卡号</th>
					<th class="ident" data-options="field:'reAdministrative',width:15,editor:'textbox'">挂号科室</th>
					<th class="ident" data-options="field:'reCallNum'">呼叫号码</th>
					<th class="ident" data-options="field:'reFigurePerson',width:15,">处理人</th>
					<th class="ident" data-options="field:'rePayFees',width:10,">缴费情况</th>
					<th class="ident" data-options="field:'reDate',width:10,formatter:function(value){
                          var unixTimestamp = new Date(value);  
                          return unixTimestamp.toLocaleDateString();}">挂号日期
                    </th> 
				</tr>
			</thead>
		</table>
	
	<div id="regjl_btn">
		<a id="addregistration" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">挂号</a> 
		<a id="regiccarddeltool"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-remove',plain:true">删除记录</a>
		<a id="regref"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">显示全部记录</a>
		<input id="regsearch" class="easyui-searchbox" 
			data-options="menu:'#regee',width:220,prompt:'请输入。。。。'">
	</div>
	<div id="regee" style=" width:90px">
		<div date-options="name:'name'">科室</div>
		<div date-options="name:'name'">医师</div>
		<div date-options="name:'name'">挂号方式</div>
		<div date-options="name:'name'">缴费情况</div>
	</div>
	<div>
		<div id="reginwin" class="easyui-window"
			style="padding: 10px;line-height: 150%;"
			data-options="
		     width: 470,
		     height:205,
		     closed: true,
		     title:'学生信息操作'
			">		
				<form id="regstuff" action="addregin" method="post">
					<table>
						<tr>
							<td>
								<div class="item">
									<input id="reireId"  name="ireId" required="required" class="easyui-textbox" data-options="label: 'Ic卡号:', width: 200,labelWidth:65,validType: ['ChackreIc']">
								</div>
							</td>
							<td>
								<div class="item">								
									 <select  class="easyui-combobox" id="rerePhysician" name="rePhysician" 
									 data-options="url:'to_Tbstaff', 
									 			   validType: ['ChackynYg'] ,
		                                           method:'get',
		                                           label: '挂号医师:',
		                                           width: 200,
		                                           labelWidth:65, 
		                                           valueField:'staffName',  
		                                           textField:'staffName',  
		                                           panelHeight:'auto' 
		                                            
		                             "> 																
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="item">
									<input id="rereCallNum"  readonly="readonly" name="reCallNum" class="easyui-textbox" data-options="label: '呼叫号码:', width: 200,labelWidth:65">
								</div>
							</td>
							<td>
							    <div class="item">
							    
							    	 <select  class="easyui-combobox" id="rereAdministrative" name="reAdministrative" 
									 data-options="url:'to_findALLdepartment', 
									  			   validType: ['ChackksByyg'] ,
		                                           method:'get',
		                                           label: '挂号科室:',
		                                           width: 200,
		                                           labelWidth:65, 
		                                           valueField:'departmentName',  
		                                           textField:'departmentName',  
		                                           panelHeight:'auto' ,		                                         
		                                            
		                             "> 							    									
								</div>
							</td>
						</tr>
						<tr>
							<td>
							    <div class="item">
									<input id="rereFigurePerson" name="reFigurePerson"  class="easyui-textbox" data-options="label: '处理人:', width: 200,labelWidth:65">
								</div>
							</td>
							<td>
							<div class="item">
									<select id="rereWay" class="easyui-combobox"  name="reWay"  data-options="label: '挂号方式:', editable:false,width:200,panelHeight:48,labelWidth:65">
									    <option value="医院">医院</option>
									    <option value="网上">网上</option>
									</select>
								</div>						
							</td>
						</tr>
						<tr>
							<td>
							<div class="item">
									<input id="rereDate" name="reDate"  class="easyui-textbox" data-options="label: '挂号日期:',  width: 200,labelWidth:65, validType: ['Chackreignid']">
								</div>								
							</td>
							<td>
								<div class="item">
									<select id="rerePayFees" class="easyui-combobox"  name="rePayFees"  data-options="label: '缴费情况:', editable:false,width:200,labelWidth:65,panelHeight:48">
									    <option value="已交">已交</option>
									    <option value="未交">未交</option>
									</select>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div>
									
								</div>
							</td>
							<td>
								<div>
								    <a id="regstu-save" class="easyui-linkbutton"data-options="iconCls:'icon-icNo'"style="width:90px">确定</a>
									<a id="regcancel" class="easyui-linkbutton"data-options="iconCls:'icon-icOk'"style="width:90px;margin-left:12px;">取消</a>
								</div>
							</td>
						</tr>
					</table>	
				</form>
			
		</div>
	</div>
</body>
</html>